<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>
          <a-col :md='5' :sm='8'>
            <a-form-item label='用途'>
              <a-input placeholder='请输入用途' v-model='queryParam.purpose' @pressEnter='searchQuery'></a-input>
            </a-form-item>
          </a-col>
          <a-col :md='4' :sm='8'>
            <span style='float: left;overflow: hidden;margin-top: 5px;' class='table-page-search-submitButtons'>
              <a-button type='primary' size='small' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' size='small' @click='searchReset' icon='reload'
                        style='margin-left: 8px'>重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
      <a-button @click='handleAdd' type='primary' icon='plus' v-has="'ActVariableConfigList:add'" size='small'>新增
      </a-button>
      <a-button type='primary' icon='download' @click="handleExportXls('审批流程变量配置')" size='small'
                v-has="'ActVariableConfigList:exportXls'">导出
      </a-button>
      <a-upload name='file' :showUploadList='false' :multiple='false' :headers='tokenHeader' :action='importExcelUrl'
                @change='handleImportExcel'>
        <a-button type='primary' icon='import' v-has="'ActVariableConfigList:importXls'" size='small'>导入</a-button>
      </a-upload>
      <a-dropdown v-if='selectedRowKeys.length > 0' v-has="'ActVariableConfigList:deleteBatch'">
        <a-menu slot='overlay'>
          <a-menu-item key='1' @click='batchDel'>
            <a-icon type='delete' />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style='margin-left: 8px' size='small'> 批量操作
          <a-icon type='down' />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref='table'
        size='middle'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
        @change='handleTableChange'>

        <div slot='filterDropdown'>
          <a-card>
            <a-checkbox-group @change='onColSettingsChange' v-model='settingColumns' :defaultValue='settingColumns'>
              <a-row>
                <template v-for='item in defColumns'>
                  <template v-if="item.key!='rowIndex'&&item.dataIndex!='action'">
                    <a-col :span='6' :key='item.key'>
                      <a-checkbox :value='item.dataIndex'>
                        {{ item.title }}
                      </a-checkbox>
                    </a-col>
                  </template>
                </template>
              </a-row>
            </a-checkbox-group>
          </a-card>
        </div>

        <a-icon slot='filterIcon' type='setting' :style="{fontSize:'16px',color:'#fff'}" />

        <template slot='fieldConditionResultsText' slot-scope='text,record'>
          <j-ellipsis v-if='text' :value='text' :length='15'></j-ellipsis>
          <j-ellipsis v-else :value='record.fieldConditionResults' :length='15'></j-ellipsis>
        </template>

        <template slot='fieldConditionCategory' slot-scope='text'>
          <span v-if="text=='depart'">部门</span>
          <span v-if="text==='role'">角色</span>
          <span v-if="text==='user'">用户</span>
          <span v-if="text==='function'">自定义方法</span>
          <span v-if="text==='variable'">常量</span>
        </template>

        <template slot='status' slot-scope='text'>
          <a-tag v-if='text==0' color='red'>停止</a-tag>
          <a-tag v-if='text==1' color='blue'>启用</a-tag>
        </template>

        <template slot='candidateCategory' slot-scope='text'>
          <span v-if="text==='default_value'">默认</span>
          <span v-if="text==='function'">自定义方法</span>
        </template>

        <span slot='action' slot-scope='text, record' class='publicFlex'>
          <a @click='handleEdit(record)' v-has="'ActVariableConfigList:edit'">编辑</a>
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item v-has="'ActVariableConfigList:delete'">
                <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
               <a-menu-item>
               <a @click='actGeneratingExpression(record)'>生成表达式</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <actVariableConfig-modal ref='modalForm' @ok='modalFormOk'></actVariableConfig-modal>
    <act-variable-generating-expression ref='expression'></act-variable-generating-expression>
  </a-card>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ActVariableConfigModal from './modules/ActVariableConfigModal'
import JEllipsis from '@/components/jeecg/JEllipsis'
import ActVariableGeneratingExpression from './modules/ActVariableGeneratingExpression'

export default {
  name: 'VariableConfigurationList',
  mixins: [JeecgListMixin],
  components: {
    ActVariableGeneratingExpression,
    ActVariableConfigModal,
    JEllipsis
  },
  data() {
    return {
      description: '审批流程变量配置管理页面',
      // 表头
      settingColumns: [],
      columns: [],
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '用途',
          align: 'center',
          dataIndex: 'purpose'
        },
        {
          title: '表名',
          align: 'center',
          dataIndex: 'tableName'
        },
        {
          title: '表描述',
          align: 'center',
          dataIndex: 'tableDescription'
        },
        {
          title: '字段',
          align: 'center',
          dataIndex: 'fieldName'
        },
        {
          title: '字段描述',
          align: 'center',
          dataIndex: 'fieldDescription'
        },
        {
          title: '字段条件',
          align: 'center',
          dataIndex: 'fieldCondition'
        },
        {
          title: '字段条件类别',
          align: 'center',
          dataIndex: 'fieldConditionCategory',
          scopedSlots: { customRender: 'fieldConditionCategory' }
        },
        {
          title: '字段条件结果',
          align: 'center',
          dataIndex: 'fieldConditionResultsText',
          scopedSlots: { customRender: 'fieldConditionResultsText' }
        },
        {
          title: '候选类别',
          align: 'center',
          dataIndex: 'candidateCategory',
          scopedSlots: { customRender: 'candidateCategory' }
        },
        {
          title: '节点编码',
          align: 'center',
          dataIndex: 'processNodeCode'
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status',
          scopedSlots: { customRender: 'status' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: {
            filterDropdown: 'filterDropdown', // 新增筛选插槽
            filterIcon: 'filterIcon', // 新增图标插槽
            customRender: 'action' // 原操作列插槽
          }
        }
      ],
      url: {
        list: '/actvariableconfig/actVariableConfig/list',
        delete: '/actvariableconfig/actVariableConfig/delete',
        deleteBatch: '/actvariableconfig/actVariableConfig/deleteBatch',
        exportXlsUrl: '/actvariableconfig/actVariableConfig/exportXls',
        importExcelUrl: 'actvariableconfig/actVariableConfig/importExcel'
      },
      dictOptions: {}
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    initDictConfig() {
    },
    //生成表达式
    actGeneratingExpression(record) {
      this.$refs.expression.open(record)
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>